Skip to content

Conversation

@rinkalpagdar
Copy link

Trac ticket: https://core.trac.wordpress.org/ticket/60726

This PR prepopulate the username into the login form after the password reset using the existing query parameter.

@github-actions
Copy link

github-actions bot commented Jan 15, 2025

The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the props-bot label.

Unlinked Accounts

The following contributors have not linked their GitHub and WordPress.org accounts: @pratik-londhe4.

Contributors, please read how to link your accounts to ensure your work is properly credited in WordPress releases.

Core Committers: Use this line as a base for the props when committing in SVN:

Props rinkalpagdar, joedolson, westonruter, peterwilsoncc.

To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook.

@github-actions
Copy link

Test using WordPress Playground

The changes in this pull request can previewed and tested using a WordPress Playground instance.

WordPress Playground is an experimental project that creates a full WordPress instance entirely within the browser.

Some things to be aware of

  • The Plugin and Theme Directories cannot be accessed within Playground.
  • All changes will be lost when closing a tab with a Playground instance.
  • All changes will be lost when refreshing the page.
  • A fresh instance is created each time the link below is clicked.
  • Every time this pull request is updated, a new ZIP file containing all changes is created. If changes are not reflected in the Playground instance,
    it's possible that the most recent build failed, or has not completed. Check the list of workflow runs to be sure.

For more details about these limitations and more, check out the Limitations page in the WordPress Playground documentation.

Test this pull request with WordPress Playground.

@pratik-londhe4
Copy link

I've tested the above patch locally, and it seems to be working as expected. The username is pre-populated when the user resets their password and navigates to the login page afterward.

@joedolson joedolson self-requested a review January 30, 2025 15:52
@peterwilsoncc
Copy link
Contributor

Please see my note on the original PR implimenting this change, it duplicates the issues discussed there.

#6928 (comment)

@joedolson joedolson requested a review from westonruter February 8, 2026 19:24
@joedolson
Copy link
Contributor

I've updated the PR to address feedback by @westonruter and @peterwilsoncc; could use a review.

joedolson and others added 2 commits February 9, 2026 11:18
Co-authored-by: Weston Ruter <westonruter@gmail.com>
joedolson and others added 2 commits February 9, 2026 13:10
Co-authored-by: Weston Ruter <westonruter@gmail.com>
Co-authored-by: Weston Ruter <westonruter@gmail.com>
@joedolson joedolson requested a review from westonruter February 9, 2026 19:18
joedolson and others added 3 commits February 9, 2026 17:00
Co-authored-by: Weston Ruter <westonruter@gmail.com>
This isn't needed; the value is already available after submitting the form.
@westonruter
Copy link
Member

westonruter commented Feb 10, 2026

@joedolson In reviewing this, I noticed that there is an existing wp-resetpass-* cookie which already contains the user. However, it isn't able to be used at present because the cookie gets deleted. What if we just reused it instead? See rinkalpagdar#1

With that change, the resulting code is much simpler:

diff --git a/src/wp-login.php b/src/wp-login.php
index c9db31826b..944aefa184 100644
--- a/src/wp-login.php
+++ b/src/wp-login.php
@@ -1000,7 +1000,6 @@ switch ( $action ) {
 
 		if ( ( ! $errors->has_errors() ) && isset( $_POST['pass1'] ) && ! empty( $_POST['pass1'] ) ) {
 			reset_password( $user, $_POST['pass1'] );
-			setcookie( $rp_cookie, ' ', time() - YEAR_IN_SECONDS, $rp_path, COOKIE_DOMAIN, is_ssl(), true );
 			login_header(
 				__( 'Password Reset' ),
 				wp_get_admin_notice(
@@ -1507,6 +1506,10 @@ switch ( $action ) {
 		}
 
 		wp_enqueue_script( 'user-profile' );
+		$rp_cookie = 'wp-resetpass-' . COOKIEHASH;
+		if ( ! $user_login && isset( $_COOKIE[ $rp_cookie ] ) && is_string( $_COOKIE[ $rp_cookie ] ) ) {
+			$user_login = sanitize_user( strtok( wp_unslash( $_COOKIE[ $rp_cookie ] ), ':' ) );
+		}
 		?>
 
 		<form name="loginform" id="loginform" action="<?php echo esc_url( site_url( 'wp-login.php', 'login_post' ) ); ?>" method="post">

@joedolson
Copy link
Contributor

@westonruter Yes, I agree - that would greatly simplify things. It seems to me that we could also still delete the cookie; we just have to do it after recovering the value. I don't think there's any real need for that cookie to persist beyond that point to meet the requirements. What do you think?

@westonruter
Copy link
Member

Yes, I agree - that would greatly simplify things.

Great. I merged those commits into this branch.

It seems to me that we could also still delete the cookie; we just have to do it after recovering the value. I don't think there's any real need for that cookie to persist beyond that point to meet the requirements. What do you think?

That sounds fine to me, although I wasn't sure where that deletion should happen. Maybe here?

// Clear any stale cookies.
if ( $reauth ) {
wp_clear_auth_cookie();
}

In any case, the cookie is already set to expire when the session ends, so it doesn't seem critical to explicitly delete. But I am not a cookie lawyer 😃

Co-authored-by: Joe Dolson <design@joedolson.com>
@westonruter
Copy link
Member

@joedolson I implemented this in b8b2f72. It seems to work. It means the cookie won't be cleared upon a visiting the resetpass login screen (the link the user clicks from the email), but rather once they click the next link to go to the login screen to use their new password.

Co-authored-by: Weston Ruter <westonruter@gmail.com>
@joedolson
Copy link
Contributor

Yeah, I'm not a cookie lawyer, either. I just play one on tv.

My only feeling about that is that if somebody previous thought it was worthwhile to delete that cookie, and we don't need to keep it longer to fix this issue, we might as well delete it.

I'm going to do a final test of this, but I think this is pretty much ready. Really happy to have been able to significantly simplify the scope of changes.

Copy link
Contributor

@joedolson joedolson left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@github-actions
Copy link

A commit was made that fixes the Trac ticket referenced in the description of this pull request.

SVN changeset: 61610
GitHub commit: 163bc04

This PR will be closed, but please confirm the accuracy of this and reopen if there is more work to be done.

@github-actions github-actions bot closed this Feb 10, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants